package com.google.googlemarket.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.googlemarket.R;
import com.google.googlemarket.bean.SubjectBean;
import com.google.googlemarket.http.BitmapHelp;
import com.google.googlemarket.http.Urls;
import com.google.googlemarket.utils.Logger;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/9/21.
 */
public class SubjectAdapter extends MyBaseAdapter<SubjectBean>{
    public SubjectAdapter(ArrayList<SubjectBean> datas) {
        super(datas);
    }

    @Override
    protected int getItemLayoutId(int position) {
        return R.layout.item_subject_list;
    }

    @Override
    protected Object createViewHolder(View convertView, int position) {
        ViewHodler viewHodler = new ViewHodler();
        viewHodler.iv_suject = (ImageView) convertView.findViewById(R.id.iv_subject);
        viewHodler.tv_subject = (TextView) convertView.findViewById(R.id.tv_subject);

        return viewHodler;
    }

    @Override
    protected void showData(int position, Object holder, SubjectBean data) {
        ViewHodler viewHodler= (ViewHodler) holder;
        Context context = ((ViewHodler) holder).iv_suject.getContext();
        String url = Urls.IMAGE+"?name="+data.url;
        Logger.i(this,"url:"+url);
        BitmapHelp.getBitmapUtils(context).display(viewHodler.iv_suject,url);
        ((ViewHodler) holder).tv_subject.setText(data.des);
    }

    class ViewHodler{
        public ImageView iv_suject;
        public TextView tv_subject;
    }
}
